<template>
	<view>
		<u-navbar title="基数申报" back-icon-color="#fff" title-color="#fff" :background="background"></u-navbar>

		<view class="bg-white mt20">
			<view class="title pl20">其他项目</view>
			<view class="row-between item">
				<view>
					<!-- <text class="required-color"></text> -->
					<text class="ml10">教师餐费</text>
				</view>
				<view><u-input :inputAlign="inputAlign" v-model="weekArr.teacher_income_amount" placeholder="金额" :type="type" :border="border" /></view>
			</view>
			<u-line color="#F6F6F6" />
			<view class="row-between item">
				<view>
					<!-- <text class="required-color"></text> -->
					<text class="ml10">临时收入</text>
				</view>
				<view><u-input :inputAlign="inputAlign" v-model="weekArr.other_income_amount" placeholder="金额" :type="type" :border="border" /></view>
			</view>
		</view>

		<view class="bg-white mt20">
			<view class="title pl20">小学学生人数</view>
			<view class="row-between item">
				<view>
					<!-- <text class="required-color">*</text> -->
					<text class="ml10">午餐</text>
				</view>
				<view><u-input :inputAlign="inputAlign" v-model="primary_data.lunch_nums" placeholder="人数" :type="type" :border="border" /></view>
			</view>
			<u-line color="#F6F6F6" />
			<view class="row-between item">
				<view>
					<!-- <text class="required-color">*</text> -->
					<text class="ml10">晚餐1</text>
				</view>
				<view><u-input :inputAlign="inputAlign" v-model="primary_data.all_nums" placeholder="人数" :type="type" :border="border" /></view>
			</view>
			<u-line color="#F6F6F6" />
			<view class="row-between item">
				<view>
					<!-- <text class="required-color">*</text> -->
					<text class="ml10">晚餐2</text>
				</view>
				<view><u-input :inputAlign="inputAlign" v-model="primary_data.dinner_nums" placeholder="人数" :type="type" :border="border" /></view>
			</view>
		</view>

		<view class="bg-white mt20">
			<view class="title pl20">小学收费标准</view>
			<view class="row-between item">
				<view>
					<!-- <text class="required-color">*</text> -->
					<text class="ml10">午餐</text>
				</view>
				<view><u-input :inputAlign="inputAlign" v-model="primary_data.lunch_amount" placeholder="金额" :type="type" :border="border" /></view>
			</view>
			<u-line color="#F6F6F6" />
			<view class="row-between item">
				<view>
					<!-- <text class="required-color">*</text> -->
					<text class="ml10">晚餐1</text>
				</view>
				<view><u-input :inputAlign="inputAlign" v-model="primary_data.all_amount" placeholder="金额" :type="type" :border="border" /></view>
			</view>
			<u-line color="#F6F6F6" />
			<view class="row-between item">
				<view>
					<!-- <text class="required-color">*</text> -->
					<text class="ml10">晚餐2</text>
				</view>
				<view><u-input :inputAlign="inputAlign" v-model="primary_data.dinner_amount" placeholder="金额" :type="type" :border="border" /></view>
			</view>
		</view>

		<view class="" v-if="is_junior">
			<view class="bg-white mt20">
				<view class="title pl20">初中学生人数</view>
				<view class="row-between item">
					<view>
						<!-- <text class="required-color">*</text> -->
						<text class="ml10">午餐</text>
					</view>
					<view><u-input :inputAlign="inputAlign" v-model="junior_data.lunch_nums" placeholder="人数" :type="type" :border="border" /></view>
				</view>
				<u-line color="#F6F6F6" />
				<view class="row-between item">
					<view>
						<!-- <text class="required-color">*</text> -->
						<text class="ml10">晚餐1</text>
					</view>
					<view><u-input :inputAlign="inputAlign" v-model="junior_data.all_nums" placeholder="人数" :type="type" :border="border" /></view>
				</view>
				<u-line color="#F6F6F6" />
				<view class="row-between item">
					<view>
						<!-- <text class="required-color">*</text> -->
						<text class="ml10">晚餐2</text>
					</view>
					<view><u-input :inputAlign="inputAlign" v-model="junior_data.dinner_nums" placeholder="人数" :type="type" :border="border" /></view>
				</view>
			</view>

			<view class="bg-white mt20">
				<view class="title pl20">初中收费标准</view>
				<view class="row-between item">
					<view>
						<!-- <text class="required-color">*</text> -->
						<text class="ml10">午餐</text>
					</view>
					<view><u-input :inputAlign="inputAlign" v-model="junior_data.lunch_amount" placeholder="金额" :type="type" :border="border" /></view>
				</view>
				<u-line color="#F6F6F6" />
				<view class="row-between item">
					<view>
						<!-- <text class="required-color">*</text> -->
						<text class="ml10">晚餐1</text>
					</view>
					<view><u-input :inputAlign="inputAlign" v-model="junior_data.all_amount" placeholder="金额" :type="type" :border="border" /></view>
				</view>
				<u-line color="#F6F6F6" />
				<view class="row-between item">
					<view>
						<!-- <text class="required-color">*</text> -->
						<text class="ml10">晚餐2</text>
					</view>
					<view><u-input :inputAlign="inputAlign" v-model="junior_data.dinner_amount" placeholder="金额" :type="type" :border="border" /></view>
				</view>
			</view>
		</view>

		<!-- 提交按钮 -->
		<view class="submit-btn white" @click="verificationData"><view class="submit-btn-content row-center">提交</view></view>
	</view>
</template>
<script>
export default {
	data() {
		return {
			border: false,
			userinfo: {},
			is_junior: false,
			inputAlign: 'right',
			type: 'number',
			// 小学
			primary_data: {
				school_type: 1,
				lunch_amount: '',
				all_amount: '',
				dinner_amount: '',
				lunch_nums: '',
				all_nums: '',
				dinner_nums: ''
			},
			// 初中
			junior_data: {
				school_type: 2,
				lunch_amount: '',
				all_amount: '',
				dinner_amount: '',
				lunch_nums: '',
				all_nums: '',
				dinner_nums: ''
			},
			// 教师餐费和临时收入
			weekArr: {
				teacher_income_amount: "",
				other_income_amount: "",
			},
			
			background: {
				backgroundColor: '#2165F7'
			}
		};
	},
	onLoad() {
		this.baseurl = this.$u.http.config.baseUrl;
		this.userinfo = uni.getStorageSync('userinfo');

		this.getJuniorSchoolFunc();
	},
	computed: {},
	methods: {
		// 获取有初中部的小区
		getJuniorSchoolFunc() {
			let _this = this;
			let post_params = {
				review_id: this.id
			};
			this.$u.post('/api/finance/getJuniorSchool', post_params).then(res => {
				let school_arr = res.school_arr;

				if (school_arr.indexOf(_this.userinfo.bumen_id) != -1) {
					_this.is_junior = true;
				}
			});
		},
		isNull(value) {
			if (value == '' || value == 0 || value == undefined) {
				return false;
			}
			return true;
		},
		verificationData() {
			let _this = this;
			let { 
				lunch_amount, 
				all_amount,
				dinner_amount, 
				lunch_nums, 
				all_nums,
				dinner_nums 
			} = _this.primary_data;
			

			_this.primary_data.lunch_amount = !_this.isNull(lunch_amount) ? 0 : lunch_amount;
			_this.primary_data.all_amount = !_this.isNull(all_amount) ? 0 : all_amount;
			_this.primary_data.dinner_amount = !_this.isNull(dinner_amount) ? 0 : dinner_amount;
			_this.primary_data.lunch_nums = !_this.isNull(lunch_nums) ? 0 : lunch_nums;
			_this.primary_data.all_nums = !_this.isNull(all_nums) ? 0 : all_nums;
			_this.primary_data.dinner_nums = !_this.isNull(dinner_nums) ? 0 : dinner_nums;
			
			// if (!_this.isNull(lunch_nums)) {
			// 	uni.showToast({
			// 		title: '小学午餐人数必填',
			// 		icon: 'none'
			// 	});
			// 	return false;
			// }
			
			// if (!_this.isNull(all_nums)) {
			// 	uni.showToast({
			// 		title: '小学晚餐人数必填',
			// 		icon: 'none'
			// 	});
			// 	return false;
			// }
			
			// if (!_this.isNull(dinner_nums)) {
			// 	uni.showToast({
			// 		title: '小学晚餐人数必填',
			// 		icon: 'none'
			// 	});
			// 	return false;
			// }

			// if (!_this.isNull(lunch_amount)) {
			// 	uni.showToast({
			// 		title: '小学午餐金额必填',
			// 		icon: 'none'
			// 	});
			// 	return false;
			// }
			
			// if (!_this.isNull(all_amount)) {
			// 	uni.showToast({
			// 		title: '小学晚餐金额必填',
			// 		icon: 'none'
			// 	});
			// 	return false;
			// }

			// if (!_this.isNull(dinner_amount)) {
			// 	uni.showToast({
			// 		title: '小学晚餐金额必填',
			// 		icon: 'none'
			// 	});
			// 	return false;
			// }

			if (_this.is_junior) {
				let { 
					lunch_amount, 
					all_amount,
					dinner_amount, 
					lunch_nums, 
					all_nums,
					dinner_nums 
				} = _this.junior_data;
				
				_this.junior_data.lunch_amount = !_this.isNull(lunch_amount) ? 0 : lunch_amount;
				_this.junior_data.all_amount = !_this.isNull(all_amount) ? 0 : all_amount;
				_this.junior_data.dinner_amount = !_this.isNull(dinner_amount) ? 0 : dinner_amount;
				_this.junior_data.lunch_nums = !_this.isNull(lunch_nums) ? 0 : lunch_nums;
				_this.junior_data.all_nums = !_this.isNull(all_nums) ? 0 : all_nums;
				_this.junior_data.dinner_nums = !_this.isNull(dinner_nums) ? 0 : dinner_nums;
				
			// 	if (!_this.isNull(lunch_nums)) {
			// 		uni.showToast({
			// 			title: '初中午餐人数必填',
			// 			icon: 'none'
			// 		});
			// 		return false;
			// 	}
				
			// 	if (!_this.isNull(all_nums)) {
			// 		uni.showToast({
			// 			title: '初中晚餐人数必填',
			// 			icon: 'none'
			// 		});
			// 		return false;
			// 	}
				
			// 	if (!_this.isNull(dinner_nums)) {
			// 		uni.showToast({
			// 			title: '初中晚餐人数必填',
			// 			icon: 'none'
			// 		});
			// 		return false;
			// 	}

			// 	if (!_this.isNull(lunch_amount)) {
			// 		uni.showToast({
			// 			title: '初中午餐金额必填',
			// 			icon: 'none'
			// 		});
			// 		return false;
			// 	}
				
			// 	if (!_this.isNull(all_amount)) {
			// 		uni.showToast({
			// 			title: '初中晚餐金额必填',
			// 			icon: 'none'
			// 		});
			// 		return false;
			// 	}

			// 	if (!_this.isNull(dinner_amount)) {
			// 		uni.showToast({
			// 			title: '初中晚餐金额必填',
			// 			icon: 'none'
			// 		});
			// 		return false;
			// 	}
			}

			let post_params = {
				arr: [_this.primary_data]
			};

			if (_this.is_junior) {
				post_params.arr.push(_this.junior_data);
			}
			
			if(!(!_this.isNull(_this.weekArr.teacher_income_amount) && !_this.isNull(_this.weekArr.other_income_amount))) {
				post_params.weekArr = _this.weekArr;
			}
			
			this.$u.post('/api/finance/addweekfee', post_params).then(res => {
				let _tip_message = '本周基数提交成功';
				if (res != null) {
					_tip_message = res.msg;
				}

				this.$u.toast(_tip_message);
			}).catch(res => {});
		}
	}
};
</script>

<style lang="scss" scoped>
page {
	background-color: #f7f7f7;
}
.title {
	padding-top: 34rpx;
	font-weight: bold;
	overflow: hidden;
	&::before {
		content: '';
		position: absolute;
		width: 6rpx;
		height: 26rpx;
		background-color: #2045fc;
		left: 0;
		margin: 6rpx auto 0;
	}
}
.item {
	padding: 20rpx 30rpx;
}

.submit-btn {
	margin: 155rpx 30rpx 0;
	.submit-btn-content {
		width: 100%;
		padding: 20rpx;
		background-color: #2c48f2;
		border-radius: 50rpx;
	}
}
</style>
